#!/usr/bin/env python
# encoding:utf-8
'''
@author: yangyongjie
@license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited. 
@contact: deamoncao100@gmail.com
software: garner
@file: app.py
@time: 2022/8/25 14:43
@desc:
'''

import os
from flask import Flask

def create_app(config=None):
    app = Flask(__name__)
    # 加载config配置
    app.config.from_object('config.settings')

    # 加载系统环境配置
    # 根据不同的系统环境变量加载不同的配置
    if 'FLASK_CONF' in os.environ:
        app.config.from_envvar('FLASK_CONF')

    if config is not None:
        if isinstance(config,dict):
            app.config.update(config)
        elif config.endswith('.py'):
            app.config.from_pyfile(config)

    import router
    # 注册蓝图
    router.init_app(app)

    import model
    # 绑定orm对象
    model.init_app_db(app)

    return app